

(in-package :gen-res)

(defun listify-this-string (q)
  (let
      (
       (result nil)
       )
    
      (with-input-from-string (str q)
          (loop
            (let*
                (
                 (qq (read str nil))
                 )
              (when (not qq) (return))
              (setf result (append result qq))
              )))
    result
    ))

(defun this-is-a-resource-from-a-row ( the-type title row &optional out)
  (format out "(set-res '~a ~a " (first row) (second row))
  (if (equal (length title) (length row))
      (loop for i from 2 to (- (length title) 1) do 
            ; skip the first which is the type of res.
            ; also skip the second which must be the name.
        (let* (
               ( tt (nth i the-type) )
               ( p (nth i title ) )
               ( o (nth i row) )
               )
          (if tt 
              (format out "'~a \"~a\" " p o)
            (format out "'~a ~a " p o))

            ; (do-commit-slot s p o)          
          ) ; end let
        ) ; end loop
    (format t "~a <> ~a~%" (length title) (length row))
    ); end if
  (format out ")~%" )
  ) ; end defun

        
(defun llist-from-line (str)
  (let* (
         ( s (format nil " ( ~a ) " str))
         )
    (with-input-from-string (in s)
      (read in)
      )))

(defun list-from-line (in)
  (let* (
         ( str (read-line in nil))
         )
    (when str (llist-from-line str)
    )))


;;;(defun list-from-line (in)
;;;  (let*
;;;      ( (result (list)))
;;;    (loop 
;;;      (let* ( (s (read-line in nil)))
;;;        (if s 
;;;            (with-input-from-string (it s)
;;;          (loop 
;;;            (let* ( str (read it nil))
;;;              (if str
;;;            (setf result (append result (list str)))
;;;                (return result))
;;;              )))
;;;        )))))
        
(defun show-me (in-file out)
  (with-open-file (in in-file :direction :input )
    (loop (let* ( 
                 (s (read-line in nil))
                 )
            (if s (format out "~a~%" s) (return "---eof---"))
            ))))
         
(defun read-delim-in-out (in-file out-file)
  (with-open-file (in in-file :direction :input :eof-error-p nil)
    (with-open-file (out out-file :direction :output :if-exists :supersede)
      ; (format out "***")
      (let* (
             ( types (list-from-line in))
             ( titles (list-from-line in))
             )
        (loop 
          (let* (
                 (row ( list-from-line in))
                 )
            ; (format t "~{~a ~}~%" row)
            (if row
                ; (format t "-%-")
                (this-is-a-resource-from-a-row types titles row out)
              (return)
              )))))))
      
      
      
  
  
(defun read-delim (the-filename)
  (with-open-file (s the-filename :direction :input)
 
    (loop 
      (let*
          (
           (q (read-line s nil))
           )
        (when (not q) (return))
        (with-input-from-string (str q)
          (loop
            (let*
                (
                 (qq (read str nil))
                 )
              (when (not qq) (return))
              (format t "~a~5,5T" qq)
              )))
        (format t "~%")
    ))))
